package com.sport.facilities.booking.system.httptask;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;

import com.sport.facilities.booking.system.htmlchecker.MakeBookingCheckChecker;
import com.sport.facilities.booking.system.model.Booking;
import com.sport.facilities.booking.system.model.BookingCheckResult;
import com.sport.facilities.booking.system.model.MakeBookFormModel;

public class MakeBookingCheckTask extends BasicTask {
	private final String TAG = "MakeBookingCheckTask";
	private MakeBookFormModel bm = null;
	
	public MakeBookingCheckTask(Context ctx, OnTaskCompleted completeAction) {
		super(ctx);
		this.listener = completeAction;
	}

	public void fnCheckBooking(MakeBookFormModel bm) {
		try {
			this.bm = bm;
			super.onPreExecute();
			super.execute(PATH_BOOK_CHECK, bm);
		} catch (Exception e) {
			this.listener.onTaskFailed(e.getMessage());
		}
	}
	
	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		MakeBookingCheckChecker mrc = new MakeBookingCheckChecker();
		try {
			ArrayList<Booking> lst = mrc.fnGetBookingListFromHtml(result,bm);
			BookingCheckResult bcr = new BookingCheckResult();
			bcr.setLst(lst);
			bcr.setBm(bm);
			if (this.listener != null) {
				this.listener.onTaskCompleted(bcr);
			}
		} catch (Exception e) {
			this.listener.onTaskFailed(e.getMessage());
		}
	}

	public void setCompletedAction(OnTaskCompleted completeAction) {
		this.listener = completeAction;
	}
}